package com.kotasoft.ejemplohibernatevalidation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class ApellidosValidator implements ConstraintValidator<ApellidosConstraint, String> {
	
	public void initialize(ApellidosConstraint constraintAnnotation) {}

	public boolean isValid(String value, ConstraintValidatorContext context) {
		if (value == null)
			return true;
		
		String[] apellidos = value.split(" ");
		if (apellidos.length == 2) 
			return true;
		
		return false;
	}

}
